<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.bootcss.com/vue/2.5.16/vue.js"></script>
</head>
<body>
<div id="hd">
    <good :lists.sync="goods"></good>
    总计：{{totalPrice}}
</div>
<script type="text/x-template" id="buy">
    <table border="1" width="600">
        <tr>
            <th>商品名称</th><th>商品价格</th><th>商品数量</th><th>小计</th>
        </tr>
        <tr v-for="v in lists">
            <td>{{v.name}}</td>
            <td>{{v.price}}</td>
            <td><input type="text" v-model="v.num" ></td>
            <td>{{v.price*v.num}}</td>
        </tr>
    </table>
</script>
<script>
    var good={
        template:'#buy',
        props:['lists'],

    }
    var app=new Vue({
        el:'#hd',
        components:{
            good:good
        },
        computed:{
            totalPrice(){
                this.price=0;
                this.goods.forEach((v,k)=>{
                   this.price+=v.price*v.num;
                })
                return this.price;
            }
        },
        data:{
            goods:[
                {id:1,name:'华为手机',price:100,num:2},
                {id:2,name:'小米手机',price:300,num:1},
                {id:3,name:'苹果手机',price:200,num:2},
                {id:4,name:'oppo手机',price:400,num:3},
                {id:5,name:'vivo手机',price:200,num:4},
            ],
            price:0
        }
    })
</script>
</body>
</html>